package dcedit;

// Import Java SDK Classes
import javax.swing.JWindow;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.util.Timer;
import java.util.TimerTask;

// Import Application Classes
import dcedit.util.*;

/**
 * The Splash class.
 * This class is launched from DCEdit and will hide itself based on a timer delay.
 * @author dca
 * @see DCEdit#main()
 */
public class Splash extends JWindow {
   /** Serializable constant */
   public static final long serialVersionUID = 1283715205149L;

   /**
    * Constructor
    * @param owner The frame owner.  This should be the DCEdit frame.
    */
   public Splash(Frame owner) {
      super(owner);

      // Create a final reference to this splash screen.
      final Splash SPLASH_SCREEN = this;

      // Create a timer to schedule a task.
      final Timer TIMER = new Timer();
      final int DELAY = 1500; // milliseconds.

      // Define the splash screen window.
      this.init();
      this.pack();
      this.setLocationRelativeTo(null);
      this.toFront();
      this.setVisible(true);

      // Create a timer task to hide the splash screen.
      TIMER.schedule(new TimerTask() {
         @Override
         public void run() {
            // Hide the splash screen.
            SPLASH_SCREEN.setVisible(false);
         } // END run
      },DELAY);
   } // END constructor

   /** init method */
   public void init() {
      final OmniImage SPLASH = new OmniImage(DCEdit.class.getResource(Constants.SPLASH_IMAGE));
      this.getContentPane().add(SPLASH, BorderLayout.CENTER);
   } // END init
} // END class Splash